/**
 * @author Jason Pratt
 */

package edu.cmu.cs.stage3.alice.authoringtool.viewcontroller;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool;

public class PropertyGUI extends javax.swing.JPanel implements edu.cmu.cs.stage3.alice.authoringtool.util.GUIElement, edu.cmu.cs.stage3.alice.authoringtool.util.Releasable {

 protected PropertyDnDPanel propertyDnDPanel;
 protected javax.swing.JComponent propertyViewController;
 protected javax.swing.JLabel equalsLabel = new javax.swing.JLabel( " = " );

 public PropertyGUI() {
  setLayout( new javax.swing.BoxLayout( this, javax.swing.BoxLayout.X_AXIS ) );
  setOpaque( false );
 }

 public void set( AuthoringTool authoringTool, edu.cmu.cs.stage3.alice.core.Property property, boolean includeDefaults, boolean allowExpressions, edu.cmu.cs.stage3.alice.authoringtool.util.PopupItemFactory factory ) {
  clean();

  propertyDnDPanel = edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getPropertyDnDPanel( property );
  propertyViewController = edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getPropertyViewController( property, includeDefaults, allowExpressions, true, factory );

  add( propertyDnDPanel );
  add( equalsLabel );
  add( propertyViewController );
  add( javax.swing.Box.createHorizontalGlue() );
 }

 public void goToSleep() {}
 public void wakeUp() {}

 public void clean() {
  removeAll();
  if( propertyDnDPanel != null ) {
   propertyDnDPanel.release();
  }
  if( propertyViewController instanceof edu.cmu.cs.stage3.alice.authoringtool.util.Releasable ) {
   ((edu.cmu.cs.stage3.alice.authoringtool.util.Releasable)propertyViewController).release();
  }
  propertyDnDPanel = null;
  propertyViewController = null;
 }

 public void die() {
  clean();
 }

 public void release() {
  edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.releaseGUI( this );
 }

 //Rem @Override
 public void remove( java.awt.Component c ) {
  super.remove( c );
 }

}
